# _*_ coding utf-8 _*_
# FILENAME：.py
# DESCRIPTION: 
# AUTH: 
# DATE: 2022/6/610:24 上午

import sys
from PyQt5.QtWidgets import *
from PyQt5.QtSql import QSqlDatabase, QSqlQuery
import padnas as pd

def createDB():
    db = QSqlDatabase.addDatabase('QSQLITE')
    db.setDatabaseName(r'G:/Projectfile/db/database.db')

    if not db.open():
        return False

    df = pd.read_excel(r"C:\Users\chenquan\Desktop\公众号推文\test79\处理前\test1.xlsx")

    # df["F_AcquireDataTime"] = list(pd.to_datetime(df.iloc[:, 0], format='%Y-%m-%dT%H:%M:%S'))
    df["F_AcquireDataTime"]=df["F_AcquireDataTime"].astype(str)
    df["F_MeterValue"] = df["F_MeterValue"].astype(str)

    data = []
    for i in range(df.shape[0]):
        data.append(tuple(df.loc[i, :].values))

    query = QSqlQuery()

    sql = """create table Build_data1(record_date date default null,name varchar(50) not null,vals decimal(10,2) default null)
      """

    query.exec_(sql)

    for i in range(len(data)):
        query.exec_("insert into Build_data1 values{0}".format(data[i]))

    db.close()
    return True


if __name__ == '__main__':
    app = QApplication(sys.argv)
    createDB()
    sys.exit(app.exec_())
